/*
 * @Descripttion: 
 * @version: 
 * @Author: wangzhilei
 * @Date: 2021-10-06 08:38:15
 * @LastEditors: wangzhilei
 * @LastEditTime: 2021-10-07 11:14:06
 */
#include<stdlib.h>
#include<stdio.h>
#include<signal.h>
#include<unistd.h>

void output(sigset_t set){
    printf("set.val[0]=%lx\n",set.__val[0]);
}
void handler(int sig)
{
    int i;
    sigset_t sysset;
    printf("\nin handler sig=%d\n",sig);
    sigprocmask(SIG_SETMASK,NULL,&sysset);
    output(sysset);
    printf("return\n");
}
int main(int argc,char *argv[])
{
    struct sigaction act;
    sigset_t set,sysset,newset;//信号集
    //信号集置0
    sigemptyset(&set);
    sigemptyset(&newset);
    sigaddset(&set,SIGUSR1);
    sigaddset(&newset,SIGUSR2);

    printf("\nadd SIGUSR1,the value of set:");
    output(set);

    printf("\nadd SIGUSR2,the value of newset:");
    output(newset);

    printf("\nafter set proc block set,and then read to sysset");
    sigprocmask(SIG_SETMASK,&set,NULL);//屏蔽set信号集中的信号
    sigprocmask(SIG_SETMASK,NULL,&sysset);//将屏蔽的set信号集清除，并保存到sysset信号集中
    printf("system mask is:\n");
    output(sysset);

    printf("install SIGALRM,and the act.sa_mask is newset(SIGUSR2)\n");
    act.sa_handler=handler;
    act.sa_flags=0;
    act.sa_mask=newset;
    sigaction(SIGALRM,&act,NULL);
    pause();

    printf("after exec ISR\n");
    sigemptyset(&sysset);
    sigprocmask(SIG_SETMASK,NULL,&sysset);
    output(sysset);
}